﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _3._1
{
    class Square:shape
    {
        private double width;

        public Square(double width)
        {
            this.width = width;
            if (!this.check())
            {
                Console.WriteLine("正方形不合法,取默认，width为3");
                this.width = 3;
            }
        }
        public override string ToString()
        {
            double s = this.area();
            return "这是一个正方形,宽：" + width.ToString("f3") + ",面积：" + s.ToString("f3") + "\n";
        }

        public override double area()
        {
            return this.width * this.width;
        }

        public override bool check()
        {
            if (width > 0)
            {
                return true;
            }
            return false;
        }
    }
}

